﻿using EscapeZone.Mapping;
using EscapeZone.Serialization;
using Microsoft.Xna.Framework;
using XnaPlus.Common.Geometry;
using XnaPlus.StateManagement.Screens;

namespace EscapeZone.Screens
{
    public class GameScreen : MainScreen 
    {
        public Player Player { get; private set; }

        private Map m_map;
        public Map Map
        {
            get { return m_map; }
            set
            {
                m_map = value;
                Player.Position = m_map.SpawnPosition;
            }
        }

        public GameScreen(EscapeGame game, GameState states) : base(game, (ulong)states)
        {
            Player = new Player(Vector2.Zero, game, this);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Player.Score >= 50 && Map.IsInGoalZone(Player.Rect))
            {
                Game.Exit();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            if (Player.Visible)
            {
                Player.Draw(gameTime);
            }

            if (Map.Visible)
            {
                Map.Draw(gameTime);
            }
        }
    }
}